<template>
  <view class="work-container">
    <!-- 轮播图 -->
    <uni-swiper-dot class="uni-swiper-dot-box" :info="data" :current="current" field="content">
      <swiper class="swiper-box" :current="swiperDotIndex" @change="changeSwiper">
        <swiper-item v-for="(item, index) in data" :key="index">
          <view class="swiper-item" @click="clickBannerItem(item)">
            <image :src="item.image" mode="aspectFill" :draggable="false" />
          </view>
        </swiper-item>
      </swiper>
    </uni-swiper-dot>

    <!-- 宫格组件 -->
    <uni-section title="流量分析" type="line"></uni-section>
    <view class="grid-body">
      <uni-grid :column="3" :showBorder="false" @change="changeGrid">
        <uni-grid-item :index="0">
          <view class="grid-item-box">
            <uni-icons type="person-filled" size="30"></uni-icons>
            <text class="text">流量概览</text>
          </view>
        </uni-grid-item>
        <uni-grid-item :index="1">
          <view class="grid-item-box">
            <uni-icons type="staff-filled" size="30"></uni-icons>
            <text class="text">24小时流量</text>
          </view>
        </uni-grid-item>
        <uni-grid-item :index="2">
          <view class="grid-item-box">
            <uni-icons type="color" size="30"></uni-icons>
            <text class="text">逐日最小流量</text>
          </view>
        </uni-grid-item>
        <uni-grid-item :index="3">
          <view class="grid-item-box">
            <uni-icons type="settings-filled" size="30"></uni-icons>
            <text class="text">逐日用量</text>
          </view>
        </uni-grid-item>
        <uni-grid-item :index="4">
          <view class="grid-item-box">
            <uni-icons type="heart-filled" size="30"></uni-icons>
            <text class="text">区域流量</text>
          </view>
        </uni-grid-item>
        
        
      </uni-grid>
    </view>
  </view>
</template>

<script setup>
	import { ref, getCurrentInstance } from "vue"
	
	const { proxy } = getCurrentInstance()
	const current = ref(0)
	const swiperDotIndex = ref(0)
	const data = ref([{ image: '/static/images/banner/banner01.jpg' }, { image: '/static/images/banner/banner02.jpg' }, { image: '/static/images/banner/banner03.jpg' }])
	
	// 定义页面映射关系（确保顺序与宫格项一致）
	const pageMap = [
	  'traffic-overview/traffic-overview', // 索引0：流量概览
	  '24h-traffic/24h-traffic',           // 索引1：24小时流量
	  'daily-min-traffic/daily-min-traffic', // 索引2：逐日最小流量
	  'daily-usage/daily-usage',           // 索引3：逐日用量
	  'regional-traffic/regional-traffic'  // 索引4：区域流量
	];
	
	// 点击宫格项事件处理
	// const changeGrid = (e) => {
	//   const index = e.detail.index;
	//   if (pageMap[index]) {
	//     uni.navigateTo({
	//       url: pageMap[index],  // Vue3中无需额外拼接"/"
	//       fail: (err) => {
	//         console.error('跳转失败:', err);
	//         uni.showToast({ title: '页面路径错误', icon: 'error' });
	//       }
	//     });
	//   }
	// };
	
	
  
  function clickBannerItem(item) {
    console.info(item)
  }

  function changeSwiper(e) {
    current.value = e.detail.current
  }

  function changeGrid(e) {
	const index = e.detail.index;
	if (pageMap[index]) {
	  uni.navigateTo({
	    url: pageMap[index],  // Vue3中无需额外拼接"/"
	    fail: (err) => {
	      console.error('跳转失败:', err);
	      uni.showToast({ title: '页面路径错误', icon: 'error' });
	    }
	  })
	}else{
		proxy.$modal.showToast('模块建设中~')
	}
    
  }
</script>

<style lang="scss" scoped>
  /* #ifndef APP-NVUE */
  page {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    background-color: #fff;
    min-height: 100%;
    height: auto;
  }

  view {
    font-size: 14px;
    line-height: inherit;
  }
  /* #endif */

  .text {
    text-align: center;
    font-size: 26rpx;
    margin-top: 10rpx;
  }

  .grid-item-box {
    flex: 1;
    /* #ifndef APP-NVUE */
    display: flex;
    /* #endif */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 15px 0;
  }

  .uni-margin-wrap {
    width: 690rpx;
    width: 100%;
    ;
  }

  .swiper {
    height: 300rpx;
  }

  .swiper-box {
    height: 150px;
  }

  .swiper-item {
    /* #ifndef APP-NVUE */
    display: flex;
    /* #endif */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #fff;
    height: 300rpx;
    line-height: 300rpx;
  }

  @media screen and (min-width: 500px) {
    .uni-swiper-dot-box {
      width: 400px;
      /* #ifndef APP-NVUE */
      margin: 0 auto;
      /* #endif */
      margin-top: 8px;
    }

    .image {
      width: 100%;
    }
  }
</style>
